//
//  YYEWrongTopicViewController.m
//  YuYingEDU
//
//  Created by zl on 2018/3/20.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYEWrongTopicViewController.h"
#import "YYEExampleViewController.h"

@interface YYEWrongTopicViewController ()

@property (nonatomic,strong) UILabel *label1;
@property (nonatomic,strong) UILabel *label3;
@property (nonatomic,strong) UILabel *label4;
@property (nonatomic,strong) UIButton *btn4;


@end

@implementation YYEWrongTopicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = GeneralBackColor;
    
    UIButton *btn = [UIButton buttonWithframe:CGRectMake(0, 0, 30, 30) text:@"" font:SystemFont(14) textColor:@"#666666" backgroundColor:nil normal:@"shanchu" selected:nil];
    [btn addTarget:self action:@selector(delAction) forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    //
    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 150)];
    baseView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:baseView];
    
    
    UIImageView *imgView = [UIImageView imgViewWithframe:CGRectMake((kScreenWidth-90)/2, 30, 90, 90) icon:@"dayuan"];
    [baseView addSubview:imgView];
    
    // 8
    UILabel *label1 = [UILabel labelWithframe:CGRectMake(0, 20, imgView.jc_width, 15) text:@"" font:SystemFont(14) textAlignment:NSTextAlignmentCenter textColor:@"#2daaff"];
    [imgView addSubview:label1];
    self.label1 = label1;
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, label1.jc_bottom+10, 70, 1)];
    line.backgroundColor = [UIColor colorWithHexString:@"#2daaff"];
    [imgView addSubview:line];

    UILabel *label2 = [UILabel labelWithframe:CGRectMake(0, line.jc_bottom+6, imgView.jc_width, 15) text:@"当前错题数" font:SystemFont(14) textAlignment:NSTextAlignmentCenter textColor:@"#2daaff"];
    [imgView addSubview:label2];
    
    //
    UIView *baseView1 = [[UIView alloc] initWithFrame:CGRectMake(0, baseView.jc_bottom+17, kScreenWidth, 80)];
    baseView1.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:baseView1];
    
    UIButton *btn1 = [UIButton buttonWithframe:CGRectMake(21, 0, 150, 40) text:@"已纠正错题数" font:SystemFont(14) textColor:@"#666666" backgroundColor:nil normal:@"jiuzhen" selected:nil];
    btn1.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    btn1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [baseView1 addSubview:btn1];
    
    // 4
    UILabel *label3 = [UILabel labelWithframe:CGRectMake(kScreenWidth-50-21, btn1.jc_y, 50, btn1.jc_height) text:@"" font:SystemFont(14) textAlignment:NSTextAlignmentRight textColor:@"#666666"];
    [baseView1 addSubview:label3];
    self.label3 = label3;

    
    UIView *line2 = [[UIView alloc] initWithFrame:CGRectMake(0, btn1.jc_bottom, kScreenWidth, 1)];
    line2.backgroundColor = [UIColor colorWithHexString:@"#c9c9c9"];
    [baseView1 addSubview:line2];
    
    UIButton *btn2 = [UIButton buttonWithframe:CGRectMake(21, line2.jc_bottom, 150, 40) text:@"历史累积错题数" font:SystemFont(14) textColor:@"#666666" backgroundColor:nil normal:@"cuoti" selected:nil];
    btn2.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    btn2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [baseView1 addSubview:btn2];
    
    // 2
    UILabel *label4 = [UILabel labelWithframe:CGRectMake(kScreenWidth-50-21, btn2.jc_y, 50, btn2.jc_height) text:@"" font:SystemFont(14) textAlignment:NSTextAlignmentRight textColor:@"#666666"];
    [baseView1 addSubview:label4];
    self.label4 = label4;

    //
    UIView *baseView2 = [[UIView alloc] initWithFrame:CGRectMake(0, baseView1.jc_bottom+15, kScreenWidth, 40)];
    baseView2.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:baseView2];
    
    UILabel *label5 = [UILabel labelWithframe:CGRectMake(21, 0, 135, baseView2.jc_height) text:@"答对后自动移除错题" font:SystemFont(14) textAlignment:0 textColor:@"#666666"];
    [baseView2 addSubview:label5];
    
    UIButton *btn3 = [UIButton buttonWithframe:CGRectMake(kScreenWidth-35-20, 10, 35, 20) text:@"" font:SystemFont(14) textColor:@"#666666" backgroundColor:nil normal:@"kai" selected:@"guang"];
    [baseView2 addSubview:btn3];
    
    //
    UIButton *btn4 = [UIButton buttonWithframe:CGRectMake((kScreenWidth-250)/2, kScreenHeight-40-24-kTopHeight, 250, 40) text:@"开始纠正错题" font:SystemFont(14) textColor:@"#ffffff" backgroundColor:@"#2daaff" normal:@"" selected:@""];
    [self.view addSubview:btn4];
    btn4.layer.cornerRadius = 20;
    btn4.layer.masksToBounds = YES;
    self.btn4 = btn4;
    [btn4 addTarget:self action:@selector(jiuZHengAction) forControlEvents:UIControlEventTouchUpInside];
    
    [self getWrongQuestion];
}

- (void)jiuZHengAction
{
    YYEExampleViewController *vc = [[YYEExampleViewController alloc]init];
//    vc.title = @"错题记录";
    vc.mark = 1;
    [self.navigationController pushViewController:vc animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getWrongQuestion {
    
    NSDictionary *dic = @{
                          //                          @"cid":self.cid,
                          //                          @"p":@(self.page),
                          //                          @"size":@10,
                          @"uid":[LoginModel shareLogin].uid,
                          @"username":[LoginModel shareLogin].username,
                          @"token":[LoginModel shareLogin].token
                          };
    [SVProgressHUD show];
    [AFNHelper post:WrongQuestion parameters:dic success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"status"] isEqual:@1]) {
            
            self.label1.text = [responseObject[@"data"][@"present"] stringValue];
            self.label3.text = [responseObject[@"data"][@"know"] stringValue];
            self.label4.text = [responseObject[@"data"][@"count"] stringValue];
            
            if ([self.label1.text isEqualToString:@"0"]) {
                
                self.btn4.userInteractionEnabled = NO;
                self.btn4.backgroundColor = [UIColor colorWithHexString:@"#909090"];
            }
        }
        //        [SVProgressHUD showWithStatus:responseObject[@"message"]];
        [SVProgressHUD dismiss];
        
    } faliure:^(id error) {
        
        NSLog(@"请求失败");
        [SVProgressHUD showWithStatus:ShowError];
        [SVProgressHUD dismissWithDelay:0.5];
        
    }];
    
}

- (void)delAction
{
    NSDictionary *dic = @{
                          //                          @"cid":self.cid,
                          //                          @"p":@(self.page),
                          //                          @"size":@10,
                          @"uid":[LoginModel shareLogin].uid,
                          @"username":[LoginModel shareLogin].username,
                          @"token":[LoginModel shareLogin].token
                          };
    [SVProgressHUD show];
    [AFNHelper post:DelWrong parameters:dic success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"status"] isEqual:@1]) {
            
            self.label1.text = @"0";
            self.label3.text = @"0";
            self.label4.text = @"0";
            self.btn4.userInteractionEnabled = NO;
            self.btn4.backgroundColor = [UIColor colorWithHexString:@"#909090"];
        }
        [SVProgressHUD showWithStatus:responseObject[@"message"]];
        [SVProgressHUD dismiss];
        
    } faliure:^(id error) {
        
        NSLog(@"请求失败");
        [SVProgressHUD showWithStatus:ShowError];
        [SVProgressHUD dismissWithDelay:0.5];
        
    }];
}

@end
